package com.xbongbong.pro.statistic.model.impl;

import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.pro.domain.dao.DataWarningHistoryDao;
import com.xbongbong.pro.domain.entity.DataWarningHistoryEntity;
import com.xbongbong.pro.statistic.model.DataWarningHistoryModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

/**
 * @ClassName DataWarningHistoryModelImpl
 * @Description 数据预警历史记录
 * @Author mengna.Deng
 * @Date 2021/4/15 19:36
 * @Version 1.0
 */
@Service("dwHistoryModel")
public class DataWarningHistoryModelImpl implements DataWarningHistoryModel {
    @Resource
    private DataWarningHistoryDao dataWarningHistoryDao;

    @Override
    public Integer insert(DataWarningHistoryEntity entity){
        return dataWarningHistoryDao.insert(entity);
    }

    @Override
    public Integer update(DataWarningHistoryEntity entity){
        return dataWarningHistoryDao.update(entity);
    }

    @Override
    public List<DataWarningHistoryEntity> findEntitys(Map<String, Object> param) {
        return dataWarningHistoryDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return dataWarningHistoryDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(DataWarningHistoryEntity entity){

        if(entity.getId() == null || entity.getId().equals(0L)) {
            return dataWarningHistoryDao.insert(entity);
        }
        return dataWarningHistoryDao.update(entity);
    }

    @Override
    public void insertBatch(List<DataWarningHistoryEntity> entityList) {
        dataWarningHistoryDao.insertBatch(entityList);
    }

    @Override
    public DataWarningHistoryEntity getByKey(Long key, String corpid) {
        return dataWarningHistoryDao.getByKey(key, corpid);
    }

    @Override
    public void invalidBatch(String corpid, List<Long> idIn) {
        dataWarningHistoryDao.invalidBatch(corpid, idIn);
    }

    @Override
    public List<DataWarningHistoryEntity> queryByDataWarningId(String corpid, Long dataWarningId, Integer num) {
        return dataWarningHistoryDao.queryByDataWarningId(corpid,dataWarningId,num);
    }

    @Override
    public Integer getTodayExecutedCount(String corpid) {
        // 当前零点
        long zero = DateTimeUtil.getTodayInt();
        return dataWarningHistoryDao.getTodayExecutedCount(corpid,zero);
    }

    @Override
    public Integer batchPhysicalDelete( Long endTime, List<String> corpidIn) {
        return dataWarningHistoryDao.batchPhysicalDelete(endTime,corpidIn);
    }

}
